package com.sina.weibo;

import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.sina.weibo.models.Account;
import com.sina.weibo.models.User;
import com.sina.weibo.view.AccountListItemView;
import com.sina.weibo.view.BaseLayout;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class AccountManager extends BaseActivity
  implements ListItemEventHandler
{
  public static final int DELETE_ITEM = 0;
  public static final String KEY_ITEM_POSITION = "position";
  public static final int PRE_DELETE_ITEM = 1;
  private static List<Account> mAccounts;
  private static List<Integer> mStateList;
  Handler handler;
  private boolean isEditState = 0;
  private ListView lvAccount;
  private AccountAdapter mAdapter;
  private Dialog mPgDialog;
  private LoginTask mTask;
  private boolean mTaskFree = 1;

  public AccountManager()
  {
    AccountManager.1 local1 = new AccountManager.1(this);
    this.handler = local1;
  }

  private void removeItem(int paramInt)
  {
    String str = ((Account)mAccounts.get(paramInt)).user;
    User localUser = StaticInfo.mUser;
    if (str.equals(localUser))
      Utils.cleanUserFile(getCacheDir().getAbsolutePath());
    Object localObject1 = mAccounts.remove(paramInt);
    Object localObject2 = mStateList.remove(paramInt);
  }

  private void showProgress(int paramInt)
  {
    Dialog localDialog = Utils.createProgressDialog(paramInt, this, 1);
    this.mPgDialog = localDialog;
    this.mPgDialog.show();
  }

  public void dismissProgressBar()
  {
  }

  public void handleListItemEvent(int paramInt1, int paramInt2)
  {
    switch (paramInt1)
    {
    default:
    case 0:
    case 1:
    }
    while (true)
    {
      return;
      Message localMessage1 = new Message();
      localMessage1.what = 0;
      Bundle localBundle1 = new Bundle();
      localBundle1.putInt("position", paramInt2);
      localMessage1.setData(localBundle1);
      boolean bool1 = this.handler.sendMessage(localMessage1);
      continue;
      Message localMessage2 = new Message();
      localMessage2.what = 1;
      Bundle localBundle2 = new Bundle();
      localBundle2.putInt("position", paramInt2);
      localMessage2.setData(localBundle2);
      boolean bool2 = this.handler.sendMessage(localMessage2);
    }
  }

  protected void handleTitleBarEvent(int paramInt)
  {
    int i = 2131427528;
    switch (paramInt)
    {
    default:
    case 0:
    case 1:
    }
    while (true)
    {
      return;
      int j;
      if (this.isEditState)
      {
        j = 0;
        label39: this.isEditState = j;
        if (!this.isEditState)
          break label139;
        String str1 = getString(2131427528);
        String str2 = getString(2131427664);
        String str3 = getString(2131427671);
        setTitleBar(1, str1, str2, str3);
      }
      int k;
      while (true)
      {
        if ((mStateList != null) && (mStateList.size() != 0))
        {
          k = 0;
          int m = mStateList.size();
          if (k < m)
            break label177;
        }
        this.mAdapter.notifyDataSetChanged();
        break;
        j = 1;
        break label39;
        label139: String str4 = getString(2131427528);
        String str5 = getString(2131427664);
        String str6 = getString(2131427663);
        setTitleBar(1, str4, str5, str6);
      }
      label177: String str7 = ((Account)mAccounts.get(k)).user;
      if (str7 != null)
      {
        String str8 = StaticInfo.mUsername;
        if (str7.equalsIgnoreCase(str8))
        {
          localList1 = mStateList;
          if (this.isEditState);
          for (i = 4; ; i = 0)
          {
            Integer localInteger1 = Integer.valueOf(i);
            Object localObject1 = localList1.set(k, localInteger1);
            k += 1;
            break;
          }
        }
      }
      List localList1 = mStateList;
      if (this.isEditState);
      for (i = 5; ; i = 1)
      {
        Integer localInteger2 = Integer.valueOf(i);
        Object localObject2 = localList1.set(k, localInteger2);
        break;
      }
      List localList2 = mAccounts;
      String str9 = StaticInfo.mUsername;
      Account localAccount1 = AccountHelper.findAccount(localList2, str9);
      List localList3 = mAccounts;
      AccountHelper.saveAccounts(this, localList3);
      if ((localAccount1 == null) && (mAccounts != null) && (mAccounts.size() != 0))
      {
        if (!this.mTaskFree)
          continue;
        Account localAccount2 = (Account)mAccounts.get(0);
        LoginTask localLoginTask1 = new LoginTask();
        this.mTask = localLoginTask1;
        LoginTask localLoginTask2 = this.mTask;
        String[] arrayOfString = new String[2];
        String str10 = localAccount2.user;
        arrayOfString[0] = str10;
        String str11 = localAccount2.pass;
        arrayOfString[1] = str11;
        AsyncTask localAsyncTask = localLoginTask2.execute(arrayOfString);
        continue;
      }
      List localList4 = mAccounts;
      AccountHelper.saveAccounts(this, localList4);
      finish();
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setView(2130903044);
    String str1 = getString(2131427528);
    String str2 = getString(2131427664);
    String str3 = getString(2131427663);
    setTitleBar(1, str1, str2, str3);
    this.isEditState = 0;
    ListView localListView1 = (ListView)findViewById(2131623948);
    this.lvAccount = localListView1;
    AccountAdapter localAccountAdapter1 = new AccountAdapter(null);
    this.mAdapter = localAccountAdapter1;
    ListView localListView2 = this.lvAccount;
    AccountAdapter localAccountAdapter2 = this.mAdapter;
    localListView2.setAdapter(localAccountAdapter2);
    ListView localListView3 = this.lvAccount;
    AccountManager.2 local2 = new AccountManager.2(this);
    localListView3.setOnItemClickListener(local2);
    mAccounts = AccountHelper.loadAccounts(this);
    int j;
    if ((mAccounts != null) && (mAccounts.size() != 0))
    {
      int i = mAccounts.size();
      mStateList = new ArrayList(i);
      j = 0;
      int k = mAccounts.size();
      if (j < k);
    }
    while (true)
    {
      return;
      String str4 = ((Account)mAccounts.get(j)).user;
      if (str4 != null)
      {
        String str5 = StaticInfo.mUsername;
        if (str4.equals(str5))
        {
          List localList1 = mStateList;
          Integer localInteger1 = Integer.valueOf(0);
          localList1.add(j, localInteger1);
        }
      }
      while (true)
      {
        j += 1;
        break;
        List localList2 = mStateList;
        Integer localInteger2 = Integer.valueOf(1);
        localList2.add(j, localInteger2);
      }
      MainTabActivity.mMode = 0;
      Intent localIntent1 = new Intent(this, MainTabActivity.class);
      Intent localIntent2 = localIntent1.putExtra("MODE_KEY", 0);
      Intent localIntent3 = localIntent1.setAction("com.sina.weibo.action.switchuser_activity_on_stack_top");
      startActivity(localIntent1);
    }
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    int i;
    if (paramInt == 4)
      if (!this.mTaskFree)
      {
        boolean bool1 = this.mTask.cancel(1);
        i = 1;
      }
    while (true)
    {
      return i;
      if (this.isEditState)
      {
        boolean bool3 = this.ly.rightButton.performClick();
        i = 1;
        continue;
      }
      boolean bool4 = this.ly.leftButton.performClick();
      i = 1;
      continue;
      boolean bool2 = super.onKeyDown(paramInt, paramKeyEvent);
    }
  }

  protected void onPause()
  {
    super.onPause();
    List localList = mAccounts;
    AccountHelper.saveAccounts(this, localList);
  }

  public void showProgressBar()
  {
  }

  class AccountAdapter extends BaseAdapter
  {
    private AccountAdapter()
    {
    }

    public int getCount()
    {
      if (AccountManager.mAccounts == null);
      for (int i = 1; ; i = AccountManager.mAccounts.size() + 1)
        return i;
    }

    public Object getItem(int paramInt)
    {
      return Integer.valueOf(paramInt);
    }

    public long getItemId(int paramInt)
    {
      return paramInt;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      int i = AccountManager.mAccounts.size();
      View localView;
      if (paramInt == i)
      {
        localView = ((LayoutInflater)AccountManager.this.getSystemService("layout_inflater")).inflate(2130903043, null);
        ImageView localImageView1 = (ImageView)localView.findViewById(2131623946);
        TextView localTextView = (TextView)localView.findViewById(2131623944);
        ImageView localImageView2 = (ImageView)localView.findViewById(2131623947);
        Drawable localDrawable = AccountManager.this.getResources().getDrawable(2130837509);
        localImageView1.setImageDrawable(localDrawable);
        localTextView.setText(2131427712);
        localTextView.setPadding(0, 18, 0, 18);
        localImageView2.setVisibility(4);
        localView.setBackgroundResource(2130837962);
      }
      AccountManager localAccountManager1;
      Account localAccount;
      int j;
      AccountManager localAccountManager2;
      int k;
      for (Object localObject = localView; ; localObject = new AccountListItemView(localAccountManager1, localAccount, k, j, localAccountManager2))
      {
        return localObject;
        localAccountManager1 = AccountManager.this;
        localAccount = (Account)AccountManager.mAccounts.get(paramInt);
        j = ((Integer)AccountManager.mStateList.get(paramInt)).intValue();
        localAccountManager2 = AccountManager.this;
        k = paramInt;
      }
    }
  }

  public class LoginTask extends AsyncTask<String, Void, Boolean>
  {
    public LoginTask()
    {
    }

    protected Boolean doInBackground(String[] paramArrayOfString)
    {
      String str1 = paramArrayOfString[0];
      String str2 = paramArrayOfString[1];
      try
      {
        User localUser = RPCHelper.getInstance(AccountManager.this.getBaseContext()).login(str1, str2);
        if (localUser != null)
        {
          StaticInfo.mUser = localUser;
          StaticInfo.mPassword = str2;
          StaticInfo.mUsername = str1;
        }
        Boolean localBoolean;
        for (localObject = Boolean.valueOf(1); ; localObject = localBoolean)
        {
          return localObject;
          localBoolean = Boolean.valueOf(0);
        }
      }
      catch (RPCHelper.HttpException localHttpException)
      {
        while (true)
          Object localObject = Boolean.valueOf(0);
      }
    }

    protected void onCancelled()
    {
      AccountManager.this.mTaskFree = 1;
      AccountManager.this.mPgDialog.dismiss();
    }

    protected void onPostExecute(Boolean paramBoolean)
    {
      if (paramBoolean.booleanValue())
      {
        Utils.setLoginStatus(1);
        User localUser = StaticInfo.mUser;
        String str1 = AccountManager.this.getCacheDir().getPath();
        AccountManager localAccountManager1 = AccountManager.this;
        Utils.saveUserFile(localUser, str1, localAccountManager1);
        SharedPreferences.Editor localEditor1 = AccountManager.this.getSharedPreferences("weibo", 0).edit();
        String str2 = StaticInfo.mUsername;
        SharedPreferences.Editor localEditor2 = localEditor1.putString("username", str2);
        String str3 = StaticInfo.mPassword;
        SharedPreferences.Editor localEditor3 = localEditor1.putString("password", str3);
        boolean bool = localEditor1.commit();
        AccountManager localAccountManager2 = AccountManager.this;
        Intent localIntent1 = new Intent("sina.weibo.action.SWITCHUSERDONE");
        localAccountManager2.sendBroadcast(localIntent1);
        AccountManager localAccountManager3 = AccountManager.this;
        Intent localIntent2 = new Intent("com.sina.weibo.action.SWITCHUSER");
        localAccountManager3.sendBroadcast(localIntent2);
        AccountManager localAccountManager4 = AccountManager.this;
        Intent localIntent3 = new Intent(localAccountManager4, MainTabActivity.class);
        Intent localIntent4 = localIntent3.putExtra("MODE_KEY", 0);
        Intent localIntent5 = localIntent3.setAction("sina.weibo.action.UPDATEHOME");
        AccountManager.this.startActivity(localIntent3);
      }
      while (true)
      {
        AccountManager.this.mPgDialog.dismiss();
        return;
        AccountManager localAccountManager5 = AccountManager.this;
        String str4 = AccountManager.this.getString(2131427410);
        Toast localToast = Toast.makeText(localAccountManager5, str4, 1);
      }
    }

    protected void onPreExecute()
    {
      AccountManager.this.mTaskFree = 0;
      AccountManager.this.showProgress(2131427396);
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.AccountManager
 * JD-Core Version:    0.6.0
 */